"""
author: Jackson Black
time: 2023-08-20 14-41-52 
"""


# r:读   w：覆盖写  x：创建写  a：追加写  b：二进制模式  t：文本模式  +：更新
def with_open_file():
    # 底层实现文件的关闭
    with open('../data/file1.txt', 'r+', encoding='utf-8') as f:
        print(f.readline())
        f.writelines("\n写入一行内容")


def open_file():
    f = None
    try:
        f = open("../data/file1.txt", "r+", encoding="utf-8")
        for line in f:
            print(line)
    except FileNotFoundError:
        print('无法打开指定的文件!')
    except LookupError:
        print('指定了未知的编码!')
    except UnicodeDecodeError:
        print('读取文件时解码错误!')
    finally:
        f.close()


if __name__ == "__main__":
    # read_file()
    open_file()
